import { ApiProperty, getSchemaPath, ApiExtraModel } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { ApiRes, PaginationDto } from '.';

export enum HouseStatus {
  inReview = 1, //审核中
  success = 2, //审核成功
  fail = 3, //审核失败
}

export class IdCardUrl {
  @ApiProperty({ description: '身份证正面', required: true })
  @Rule(RuleType.string().required().error(new Error('身份证正面不能为空')))
  idcardFrontUrl: string;
  @ApiProperty({ description: '身份证背面', required: true })
  @Rule(RuleType.string().required().error(new Error('身份证背面不能为空')))
  idcardBackUrl: string;
}

export class HouseIdRequired {
  @ApiProperty({ description: '房屋id', required: true })
  @Rule(RuleType.number().required().error(new Error('房屋id不能为空')))
  id: number;
}

export class HouseId {
  @ApiProperty({ description: '房屋id' })
  id: number;
}

export class HouseStatusDto {
  @ApiProperty({
    description: '审核状态1审核中2通过3拒绝',
    default: HouseStatus.inReview,
    required:true
  })
  @Rule(RuleType.number().required().error(new Error('审核状态不能为空')))
  status: number;
}

export class HouseItem extends HouseId {
  @ApiProperty({ description: '小区坐标' })
  point: string;

  @ApiProperty({ description: '小区名称' })
  pointName: string;

  @ApiProperty({ description: '小区楼栋信息' })
  building: string;

  @ApiProperty({ description: '小区房间信息' })
  room: string;

  @ApiProperty({
    description: '审核状态1审核中2通过3拒绝',
    default: HouseStatus.inReview,
  })
  status: number;
}

export class HouseAddDto extends IdCardUrl {
  @ApiProperty({ description: '小区坐标', required: true })
  @Rule(RuleType.string().required().error(new Error('小区坐标不能为空')))
  point: string;

  @ApiProperty({ description: '小区名称', required: true })
  @Rule(RuleType.string().required().error(new Error('小区名称不能为空')))
  pointName: string;

  @ApiProperty({ description: '小区楼栋信息', required: true })
  @Rule(RuleType.string().required().error(new Error('小区楼栋信息不能为空')))
  building: string;

  @ApiProperty({ description: '小区房间信息', required: true })
  @Rule(RuleType.string().required().error(new Error('小区房间信息不能为空')))
  room: string;
}

export class HouseEditDto extends HouseAddDto {
  @ApiProperty({ description: '房屋id', required: true })
  @Rule(RuleType.number().required().error(new Error('房屋id不能为空')))
  id: number;
}
export class HouseItemDetails extends HouseEditDto{
  @ApiProperty({ description: '业主名' })
  userName: string
  @ApiProperty({ description: '业主手机号' })
  userPhone: string
  @ApiProperty({
    description: '审核状态1审核中2通过3拒绝',
  })
  status: number;
}

@ApiExtraModel(HouseItemDetails)
export class HouseItemRes {
  @ApiProperty({
    type: 'array',
    items: {
      $ref: getSchemaPath(HouseItemDetails),
    },
  })
  list: HouseItemDetails[];
  @ApiProperty({ type: PaginationDto, description: '分页' })
  pagination: PaginationDto;
}
export class HouseItemResDto extends ApiRes<HouseItemRes>(HouseItemRes) {}


export class HouseItemAuditDto extends HouseIdRequired {
  @ApiProperty({
    description: '2通过3拒绝',
    required:true
  })
  @Rule(RuleType.number().required().error(new Error('审核状态不能为空')))
  status: number;
}
